home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kiconview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.2 KB  |  282 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 1999 Torben Weis <weis@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef KICONVIEW_H
  19. #define KICONVIEW_H
  20.  
  21. #include <qcursor.h>
  22. #include <qiconview.h>
  23.  
  24. #include <kdelibs_export.h>
  25.  
  26. /**
  27.  * @short A variant of QIconView that honors KDE's system-wide settings.
  28.  *
  29.  * This Widget extends the functionality of QIconView to honor the system
  30.  * wide settings for Single Click/Double Click mode, Auto Selection and
  31.  * Change Cursor over Link.
  32.  *
  33.  * There is a new signal executed(). It gets connected to either
  34.  * QIconView::clicked() or QIconView::doubleClicked() depending on the KDE
  35.  * wide Single Click/Double Click settings. It is strongly recommended that
  36.  * you use this signal instead of the above mentioned. This way you don┤t
  37.  * need to care about the current settings.
  38.  * If you want to get informed when the user selects something connect to the
  39.  * QIconView::selectionChanged() signal.
  40.  *
  41.  **/
  42. class KDEUI_EXPORT KIconView : public QIconView
  43. {
  44.   friend class KIconViewItem;
  45.   Q_OBJECT
  46.   Q_ENUMS( Mode )
  47.   Q_PROPERTY( Mode mode READ mode WRITE setMode )
  48.  
  49. public:
  50.   KIconView( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
  51.  
  52.   ~KIconView();
  53.  
  54.   /**
  55.    * KIconView has two different operating modes. Execute mode is depending
  56.    * on the configuration of single-click or double-click where the signal
  57.    * executed() will be emitted upon click/double-click.
  58.    * In Select mode, this signal will not be emitted.
  59.    *
  60.    * Default is Execute mode.
  61.    */
  62.   enum Mode { Execute, Select };
  63.  
  64.   /**
  65.    * Sets the mode to Execute or Select.
  66.    * @li In Execute mode, the signal executed()
  67.    * will be emitted when the user clicks/double-clicks an item.
  68.    * @li Select mode is
  69.    * the normal QIconView mode.
  70.    *
  71.    * Default is Execute.
  72.    */
  73.   void setMode( Mode m );
  74.  
  75.   /**
  76.    * @returns the current Mode, either Execute or Select.
  77.    */
  78.   Mode mode() const;
  79.  
  80.   /**
  81.    * Reimplemented for internal purposes
  82.    */
  83.   virtual void setFont( const QFont & );
  84.  
  85.    /**
  86.     * Set the maximum number of lines that will be used to display icon text.
  87.     * Setting this value will enable word-wrap, too.
  88.     * @since 3.3
  89.     *
  90.     * @param n Number of lines
  91.     */
  92.   void setIconTextHeight( int n );
  93.  
  94.    /**
  95.     * @return The height of icon text in lines
  96.     * @since 3.3
  97.     */
  98.   int iconTextHeight() const;
  99.  
  100.   /**
  101.    * Reimplemented for held() signal behavior internal purposes
  102.    */
  103.   virtual void takeItem( QIconViewItem * item );
  104.  
  105. signals:
  106.  
  107.   /**
  108.    * This signal is emitted whenever the user executes an iconview item.
  109.    * That means depending on the KDE wide Single Click/Double Click
  110.    * setting the user clicked or double clicked on that item.
  111.    * @param item is the pointer to the executed iconview item.
  112.    *
  113.    * Note that you may not delete any QIconViewItem objects in slots
  114.    * connected to this signal.
  115.    */
  116.   void executed( QIconViewItem *item );
  117.  
  118.   /**
  119.    * This signal is emitted whenever the user executes an iconview item.
  120.    * That means depending on the KDE wide Single Click/Double Click
  121.    * setting the user clicked or double clicked on that item.
  122.    * @param item is the pointer to the executed iconview item.
  123.    * @param pos is the position where the user has clicked
  124.    *
  125.    * Note that you may not delete any QIconViewItem objects in slots
  126.    * connected to this signal.
  127.    */
  128.   void executed( QIconViewItem *item, const QPoint &pos );
  129.  
  130.   /**
  131.    * This signal is emitted whenever the user hold something on an iconview
  132.    * during a drag'n'drop.
  133.    * @param item is the pointer to the iconview item the hold event occur.
  134.    *
  135.    * Note that you may not delete any QIconViewItem objects in slots
  136.    * connected to this signal.
  137.    */
  138.   void held( QIconViewItem *item );
  139.  
  140.   /**
  141.    * This signal gets emitted whenever the user double clicks into the
  142.    * iconview.
  143.    * @param item is the pointer to the clicked iconview item.
  144.    * @param pos is the position where the user has clicked, and
  145.    *
  146.    * Note that you may not delete any QIconViewItem objects in slots
  147.    * connected to this signal.
  148.    *
  149.    * This signal is more or less here for the sake of completeness.
  150.    * You should normally not need to use this. In most cases it's better
  151.    * to use executed() instead.
  152.    */
  153.   void doubleClicked( QIconViewItem *item, const QPoint &pos );
  154.  
  155. protected slots:
  156.   void slotOnItem( QIconViewItem *item );
  157.   void slotOnViewport();
  158.   void slotSettingsChanged(int);
  159.  
  160.   /**
  161.    * Auto selection happend.
  162.    */
  163.   void slotAutoSelect();
  164.  
  165. protected:
  166.   void emitExecute( QIconViewItem *item, const QPoint &pos );
  167.   void updateDragHoldItem( QDropEvent *e );
  168.  
  169.   virtual void focusOutEvent( QFocusEvent *fe );
  170.   virtual void leaveEvent( QEvent *e );
  171.   virtual void contentsMousePressEvent( QMouseEvent *e );
  172.   virtual void contentsMouseDoubleClickEvent ( QMouseEvent * e );
  173.   virtual void contentsMouseReleaseEvent( QMouseEvent *e );
  174.   virtual void contentsDragEnterEvent( QDragEnterEvent *e );
  175.   virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
  176.   virtual void contentsDragMoveEvent( QDragMoveEvent *e );
  177.   virtual void contentsDropEvent( QDropEvent* e );
  178.   virtual void wheelEvent( QWheelEvent *e );
  179.  
  180.   /**
  181.    * This method allows to handle correctly cases where a subclass
  182.    * needs the held() signal to not be triggered without calling
  183.    * a KIconView::contentsDrag*Event() method (which have side effects
  184.    * because they forward to QIconView).
  185.    */
  186.   void cancelPendingHeldSignal();
  187.   
  188. private slots:
  189.   void slotMouseButtonClicked( int btn, QIconViewItem *item, const QPoint &pos );
  190.   void slotDragHoldTimeout();
  191.  
  192. private:
  193.   /**
  194.    * @internal. For use by KIconViewItem.
  195.    */
  196.   QFontMetrics *itemFontMetrics() const;
  197.   /**
  198.    * @internal. For use by KIconViewItem.
  199.    */
  200.   QPixmap selectedIconPixmap( QPixmap *pix, const QColor &col ) const;
  201.  
  202.   bool m_bUseSingle;
  203.   bool m_bChangeCursorOverItem;
  204.  
  205.   QIconViewItem* m_pCurrentItem;
  206.  
  207.   QTimer* m_pAutoSelect;
  208.   int m_autoSelectDelay;
  209.  
  210. protected:
  211.   virtual void virtual_hook( int id, void* data );
  212. private:
  213.   class KIconViewPrivate;
  214.   KIconViewPrivate *d;
  215. };
  216.  
  217. class KWordWrap;
  218. /**
  219.  * @short A variant of QIconViewItem that wraps words better.
  220.  *
  221.  * KIconViewItem exists to improve the word-wrap functionality of QIconViewItem
  222.  * Use KIconViewItem instead of QIconViewItem for any iconview item you might have :)
  223.  *
  224.  * @author David Faure <david@mandrakesoft.com>
  225.  */
  226. class KDEUI_EXPORT KIconViewItem : public QIconViewItem
  227. {
  228. public:
  229.     // Need to redefine all the constructors - I want Java !
  230.     KIconViewItem( QIconView *parent )
  231.         : QIconViewItem( parent ) { init(); } // We need to call it because the parent ctor won't call our reimplementation :(((
  232.     KIconViewItem( QIconView *parent, QIconViewItem *after )
  233.         : QIconViewItem( parent, after ) { init(); }
  234.     KIconViewItem( QIconView *parent, const QString &text )
  235.         : QIconViewItem( parent, text ) { init(); }
  236.     KIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text )
  237.         : QIconViewItem( parent, after, text ) { init(); }
  238.     KIconViewItem( QIconView *parent, const QString &text, const QPixmap &icon )
  239.         : QIconViewItem( parent, text, icon ) { init(); }
  240.     KIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPixmap &icon )
  241.         : QIconViewItem( parent, after, text, icon ) { init(); }
  242.     KIconViewItem( QIconView *parent, const QString &text, const QPicture &picture )
  243.         : QIconViewItem( parent, text, picture ) { init(); }
  244.     KIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPicture &picture )
  245.         : QIconViewItem( parent, after, text, picture ) { init(); }
  246.     virtual ~KIconViewItem();
  247.  
  248.    /**
  249.     * Using this function, you can specify a custom size for the pixmap. The
  250.     * geometry of the item will be calculated to let a pixmap of the given size
  251.     * fit in the iconView without needing an update.
  252.     * This may be useful if you want to change the pixmap later without breaking
  253.     * the layout. A possible use of this function is to replace a fileItem icon
  254.     * by a larger pixmap (preview).
  255.     * @since 3.3
  256.     *
  257.     * @param size The size to use
  258.     */
  259.     void setPixmapSize( const QSize& size );
  260.  
  261.    /**
  262.     * @return The size set by setPixmapSize() or QSize( 0, 0 )
  263.     * @since 3.3
  264.     */
  265.     QSize pixmapSize() const;
  266.  
  267. protected:
  268.     void init();
  269.     virtual void calcRect( const QString& text_ = QString::null );
  270.     virtual void paintItem( QPainter *p, const QColorGroup &c );
  271.     KWordWrap *wordWrap();
  272.     void paintPixmap( QPainter *p, const QColorGroup &c );
  273.     void paintText( QPainter *p, const QColorGroup &c );
  274.  
  275. private:
  276.     KWordWrap* m_wordWrap;
  277.     struct KIconViewItemPrivate;
  278.     KIconViewItemPrivate *d;
  279. };
  280.  
  281. #endif
  282.